package common

import (
    "time"
)

// MQTT协议版本
type ProtocolVersion byte

const (
    MQTT311 ProtocolVersion = 4
    MQTT5   ProtocolVersion = 5
)

// 消息类型
type MessageType byte

const (
    CONNECT     MessageType = 1
    CONNACK     MessageType = 2
    PUBLISH     MessageType = 3
    PUBACK      MessageType = 4
    PUBREC      MessageType = 5
    PUBREL      MessageType = 6
    PUBCOMP     MessageType = 7
    SUBSCRIBE   MessageType = 8
    SUBACK      MessageType = 9
    UNSUBSCRIBE MessageType = 10
    UNSUBACK    MessageType = 11
    PINGREQ     MessageType = 12
    PINGRESP    MessageType = 13
    DISCONNECT  MessageType = 14
)

// QoS级别
type QoS byte

const (
    QoS0 QoS = 0
    QoS1 QoS = 1
    QoS2 QoS = 2
)

// MQTT数据包接口
type Packet interface {
    Type() MessageType
    Encode() ([]byte, error)
    Decode([]byte) error
}

// 客户端连接信息
type ClientInfo struct {
    ClientID        string
    Username        string
    Password        string
    KeepAlive       uint16
    CleanSession    bool
    WillTopic       string
    WillMessage     []byte
    WillQoS         QoS
    WillRetain      bool
    ProtocolVersion ProtocolVersion
}

// 发布消息
type Message struct {
    Topic     string
    Payload   []byte
    QoS       QoS
    Retain    bool
    PacketID  uint16
    Timestamp time.Time
}

// 订阅信息
type Subscription struct {
    Topic string
    QoS   QoS
}
